//
// Created by Administrator on 2023/11/24.
//
#include "bits/stdc++.h"

using namespace std;

const int N = 1010;

int dp[N][N];
int w[N], v[N];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i] >> w[i];
    }
    //i表示考虑物品 j考虑重量
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (j < v[i])
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
        }
    }
    cout << dp[n][m];
}